/*
 * oled_spi_drv.c
 *
 *  Created on: 2017年1月11日
 *      Author: gavini
 */

#include "oled_spi_drv.h"
#include <wiringPi.h>

extern spiPinDriver spiPinDrv;


/*
 * RST复位
 * CS片选信号
 * DC：数据控制切换
 * CLK：spi接口的时钟
 * SDIN：SPI接口的数据信号，本模块只写入一个方向；
 *
 * 本项目使用自定义组件模拟GPIO，为了确保逻辑程序可以
 */

void SET_OLED_DATA(){
	digitalWrite(oledDc,HIGH);
}

void SET_OLED_CMD(){
	digitalWrite(oledDc,LOW);
}

void SET_OLED_SCLK(){
	digitalWrite(oledClk,HIGH);
}

void CLR_OLED_SCLK(){
	digitalWrite(oledClk,LOW);
}

void SET_OLED_SDIN(){
	digitalWrite(oledMosi,HIGH);
}

void CLR_OLED_SDIN(){
	digitalWrite(oledMosi,LOW);
}

void SET_OLED_RST(){
	digitalWrite(oledRst,HIGH);
}

void CLR_OLED_RST(){
	digitalWrite(oledRst,LOW);
}

void SET_OLED_CS(){
	digitalWrite(oledCs,HIGH);
}

void CLR_OLED_CS(){
	digitalWrite(oledCs,LOW);
}


void initOledDrv(){
	spiPinDrv.setCmd 	= SET_OLED_CMD;
	spiPinDrv.setData 	= SET_OLED_DATA;
	spiPinDrv.setCsPin  = SET_OLED_CS;
	spiPinDrv.setRstPin = SET_OLED_RST;
	spiPinDrv.setSclkPin= SET_OLED_SCLK;
	spiPinDrv.setSdinPin= SET_OLED_SDIN;
	spiPinDrv.clrCsPin  = CLR_OLED_CS;
	spiPinDrv.clrRstPin = CLR_OLED_RST;
	spiPinDrv.clrSclkPin= CLR_OLED_SCLK;
	spiPinDrv.clrSdinPin= CLR_OLED_SDIN;
}

void aeroOledInitGpio(void)
{
	pinMode(oledClk,OUTPUT);
	pinMode(oledMosi,OUTPUT);
	pinMode(oledRst,OUTPUT);
	pinMode(oledDc,OUTPUT);
}
